package com.supreme.studyserver.service;

import com.supreme.studyserver.entity.Computer;
import com.supreme.studyserver.entity.FXPack;
import com.supreme.studyserver.entity.FXPackArray;
import com.supreme.studyserver.entity.Test;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.function.Supplier;

@Service
public class GenericsService {

    public void genericsDemo1() {
        final Test test = new Test().setFirstName("aaa").setLastName("bbb");
        final FXPack<Test> stringFXPack = new FXPack<>(test);
        final Test data = stringFXPack.getData();
        System.out.println(data);
    }

    public void genericsDemo2() {
        final Test test = new Test().setFirstName("aaa").setLastName("bbb");
        System.out.println(test);
        final FXPack<Test> stringFXPack = new FXPack<>(() -> test);
        final Test data = stringFXPack.getData();
        System.out.println(data);
    }

    public void genericsDemo3() {
        final Computer computer = new Computer().setName("intel").setMode("hash");
        final Computer result = new FXPack<>().showGenerics(() -> computer);
        System.out.println(result);
    }

    public void genericsDemoA1() {
        final Test test1 = new Test().setFirstName("aaa").setLastName("bbb");
        final Test test2 = new Test().setFirstName("aaa").setLastName("bbb");
        Test[] testArray = new Test[] {test1, test2};

        final FXPackArray<Test> stringFXPack = new FXPackArray<>(() -> testArray);
        final Test[] dataArray = stringFXPack.getDataArray();
        System.out.println(Arrays.toString(dataArray));
    }

    public void genericsDemoA2() {
        final Computer computer1 = new Computer().setName("intel").setMode("hash");
        final Computer computer2 = new Computer().setName("amd").setMode("history");
        Computer[] computerArray = new Computer[] {computer1, computer2};
        final Computer[] result = new FXPackArray<>().showGenerics(() -> computerArray);
        System.out.println(Arrays.toString(result));
    }
}
